﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Drawing;

using Wxits.Data;
using Wxits.Helper;


public partial class Admin_Dashboard : BasePage_Grid
{
    private string _id = string.Empty;

    protected static string date = string.Empty;
    protected static string UserCount = string.Empty;
    protected static string BuyAmount = string.Empty;
    protected static string CashBonus = string.Empty;
    protected static string CoinBonus = string.Empty;
    protected static string UseCash = string.Empty;
    protected static string UseCoin = string.Empty;
    protected static string RechargeCash = string.Empty;
    protected static string GetCash = string.Empty;

    private int _PageSize
    {
        set { ViewState["PageSize"] = value; }
        get
        {
            return Convert.ToInt32(ViewState["PageSize"]);
        }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (!DataCheck.CheckAuthority())
            {
                GridForm.Visible = false;
                divErr.InnerText = "请确认有访问该页权限";
                divErr.Visible = true;
                return;
            }

            _PageSize = 10;
            ShowData(0, _PageSize);
        }
    }

    private void ShowData(long PageIndex, long PageSize)
    {


        string strSQL = @" SELECT * FROM Mall_Statistics_Total";
        DataTable dt = DBAccess.ExecuteDataTable(strSQL);
        rpStatistics.DataSource = dt;
        rpStatistics.DataBind();


        strSQL = @"SELECT top 30 * FROM Mall_Statistics_Day order by id desc";
        dt = DBAccess.ExecuteDataTable(strSQL);
        gvData.DataSource = dt;
        gvData.DataBind();


        date = string.Empty;
        UserCount = string.Empty;
        BuyAmount = string.Empty;
        CashBonus = string.Empty;
        CoinBonus = string.Empty;
        UseCash = string.Empty;
        UseCoin = string.Empty;
        RechargeCash = string.Empty;
        GetCash = string.Empty;

        for (int i = 0; i < dt.Rows.Count; i++)
        {
            if (i != 0)
            {
                date += ",";
                UserCount += ",";
                BuyAmount += ",";
                CashBonus += ",";
                CoinBonus += ",";
                UseCash += ",";
                UseCoin += ",";
                RechargeCash += ",";
                GetCash += ",";
            }

            date += "'" + DataConvert.ToDateTime(dt.Rows[i]["cdate"]).ToString("MM-dd") + "'";
            UserCount += dt.Rows[i]["TotalUserCount"].ToString();
            BuyAmount += dt.Rows[0]["TotalBuyAmount"].ToString();
            CashBonus += dt.Rows[i]["TotalCashBonus"].ToString();
            CoinBonus += (DataConvert.ToDecimal(dt.Rows[i]["TotalCoinBonus"],2) / 100).ToString();
            UseCash += dt.Rows[i]["TatalUseCash"].ToString();
            UseCoin += (DataConvert.ToDecimal(dt.Rows[i]["TotalUseCoin"], 2) / 100).ToString();
            RechargeCash += dt.Rows[i]["TotalRechargeCash"].ToString();
            GetCash += dt.Rows[i]["TotalGetCash"].ToString();

        }


    }





    protected void btnTable_Click(object sender, EventArgs e)
    {
        divChart.Visible = false;
        gvData.Visible = true;
    }

    protected void btnChart_Click(object sender, EventArgs e)
    {
        divChart.Visible = true;
        gvData.Visible = false;
    }
}
